﻿using System;
using System.Reflection;

namespace PageAdmin.Utils.ORM
{
    /// <summary>
    /// 关联数据的映射特性
    /// </summary
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
    public class RelateDataAttribute : Attribute
    {
        public RelateDataAttribute(string valueKey, string relateKey = "Id",bool listSyncLoad= true, bool detailSyncLoad = true,string sqlCondition=null,string orderBy=null)
        {
            this.ValueKey = valueKey;
            this.RelateKey = relateKey;
            this.ListSyncLoad = listSyncLoad;
            this.DetailSyncLoad = detailSyncLoad;
            this.SqlCondition = sqlCondition;
            this.OrderBy = orderBy;
        }

        /// <summary>
        /// 数据的属性名称，只能是int或Ienumerable<int>
        /// </summary>
        public string ValueKey { get; set; }


        /// <summary>
        /// 关联的目标数据表的属性名称
        /// </summary>
        public string RelateKey { get; set; }


        /// <summary>
        /// 详情数据是否同步加载
        /// </summary>
        public bool DetailSyncLoad { get; set; }

        /// <summary>
        /// 列表数据是否同步加载
        /// </summary>
        public bool ListSyncLoad { get; set; }


        /// <summary>
        /// 读取的自定义条件
        /// </summary>
        public string SqlCondition { get; set; }

        /// <summary>
        /// 读取数据排序方式
        /// </summary>
        public string OrderBy { get; set; }
    }

}
